<template>
  <div class="commentlist">
    <div v-for="(item, index) in comments" :key="index">
      <div class="commentItem">
        <div class="avatar">
          <img :src="item.userinfo.user_img" alt="" v-if="item.userinfo"/>
          <img src="../../../assets/img/avatar.jpg" alt="" v-else />
        </div>
        <div class="comment">
          <p class="username" v-if="item.userinfo">
            {{ item.userinfo.name }}
          </p>
          <p class="username" v-else>无名氏</p>
          <p class="content">{{ item.comment_content }}</p>
        </div>
        <div class="data" v-if="item.userinfo">
          <p>{{ item.comment_date }}</p>
          <p class="reply" @click="replyFirst(item.comment_id)">回复</p>
        </div>
      </div>
      <CommentItem :childComment="item.child" @replyToFirst="replyFirst"/>
    </div>
    <!-- <div>
      <div class="commentItem">
        <div class="avatar">
          <img src="../../../assets/img/avatar.jpg" alt="" />
        </div>
        <div class="comment">
          <p class="username">我感觉</p>
          <p class="content">我感觉机器猫更好看一点</p>
        </div>
        <div class="data">04-24</div>
      </div>
      <CommentItem />
    </div> -->
  </div>
</template>

<script>
import CommentItem from "./CommentItem";
export default {
  name: "",
  data() {
    return {};
  },
  methods: {
    // 一级评论的回复
    replyFirst(cid){
      this.$emit('replyComment', cid)
      // console.log(cid);
      
    },
  },
  props: {
    comments: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  components: {
    CommentItem
  }
};
</script>
<style lang="less" scoped>
.commentlist {
  margin-top: 10px;
  padding: 0 10px;
  .commentItem {
    display: flex;
    padding-top: 20px;
    border-top: 1px solid #ccc;

    .avatar {
      text-align: center;
      flex: 1;
      img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
      }
    }
    .comment {
      flex: 4;
      p {
        word-break: break-all;
        margin: 5px;
        line-height: 20px;
        font-size: 14px;
      }
      .username {
        color: #b5b5b5;
      }
    }
    .data {
      flex: 1;
      text-align: center;
      color: #b5b5b5;
      font-size: 12px;
      p{
          margin: 5px;
          &.reply{
            margin-top: 10px;
            color: #02a774;
          }
        }
    }
  }
}
</style>
